package com.example.tibetanmedicinechest.service.impl;

import com.example.tibetanmedicinechest.model.Medicine;
import com.example.tibetanmedicinechest.mapper.MedicineMapper;
import com.example.tibetanmedicinechest.service.IMedicineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 编程笨蛋
 * @since 2023-08-12
 */
@Service
public class MedicineServiceImpl extends ServiceImpl<MedicineMapper, Medicine> implements IMedicineService {
    @Autowired
    MedicineMapper medicineMapper;
    @Override
    public List<Map<String, Object>> selectAllMedicine() {
        List<Medicine> medicines = medicineMapper.selectList(null);
        List<Map<String,Object>> datas = new ArrayList<>();
        for (Medicine medicine:medicines) {
            Map<String,Object> data = new HashMap<>();
            data.put("id",medicine.getId());
            data.put("images",medicine.getImage());
            data.put("name",medicine.getName());
            data.put("function",medicine.getFunctions());
            data.put("method",medicine.getMethod());
            data.put("introduce",medicine.getIntroduce());

            datas.add(data);
        }
        return datas;
    }

    @Override
    public List<Medicine> queryMedicine(String keyword) {
        List<Medicine> medicines = medicineMapper.queryMedicine(keyword);
        return medicines;
    }

    @Override
    public Medicine selectById(Integer id) {
        Medicine medicine = medicineMapper.selectById(id);
        return medicine;
    }
}
